<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: qupen
  Date: 2016/9/18
  Time: 19:43
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<jsp:include page="../../include/head.jsp">
    <jsp:param name="title" value="产品录入"/>
</jsp:include>

<jsp:include page="../../include/tenant_header.jsp"/>

<jsp:include page="../../include/tenant_sidebar.jsp"/>

<div class="content-wrapper">
    <section class="content-header">
        <h4 class="page-title">编辑</h4>
    </section>
    <section class="content">
        <div class="box box-primary">
            <div class="box-body">
                <div class="form-horizontal">
                    <div class="sie-padding-top">
                        <div class="form-group form-group-change">
                            <label class="col-md-5 sie-left-name">机床id:</label>

                            <div class="col-md-7">
                                <input id="uniqueId" class="form-control sie-input-border sie-input-uwh" value="${data.uniqueId}" readonly="readonly">
                            </div>
                        </div>
                        <div class="form-group form-group-change">
                            <label class="col-md-5 sie-left-name">录入日期:</label>

                            <div class="col-md-7">
                                <input id="startTime" class="form-control sie-input-border sie-input-uwh" value="${data.startTime}" readonly="readonly">
                            </div>
                        </div>
                        <div class="form-group form-group-change">
                            <label class="col-md-5 sie-left-name">产品总数:</label>

                            <div class="col-md-7">
                                <input id="produtNum" class="form-control sie-input-border sie-input-uwh" value="${data.productNum}">
                            </div>
                        </div>
                        <div class="form-group form-group-change">
                            <label class="col-md-5 sie-left-name">良品数:</label>

                            <div class="col-md-7">
                                <input id="goodNum" class="form-control sie-input-border sie-input-uwh" value="${data.goodNum}">
                            </div>
                        </div>
                        <div class="form-group form-group-change">
                            <label class="col-md-5 sie-left-name">次品数:</label>

                            <div class="col-md-7">
                                <input id="badNum" class="form-control sie-input-border sie-input-uwh" value="${data.badNum}">
                            </div>
                        </div>
                        <div class="form-group form-group-change">
                            <div class="col-md-offset-5" style="margin-top: 79px;">
                                <a id="edit_button" class="solid-button-blue" href="javascript:;"
                                   style="margin-right: 30px">保存</a>
                                <a class="solid-button-orange" href="javascript:history.back(-1);">取消</a>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <%--</div>--%>
    </section>
</div>
<jsp:include page="../../include/foot.jsp"/>
<script>
    $(function(){
        $("#edit_button").click(function(){
            if($("#produtNum").val().trim() == "" || $("#goodNum").val().trim() == "" || $("#badNum").val().trim() == ""){
                swal("数量不能为空!", "", "error");
                return;
            }
            $.ajax({
                url:"/partner/{tenant}/api/v1/product/update".replace("{tenant}", getKeyByUrl()),
                type:"POST",
                contentType:"application/json",
                data:JSON.stringify({
                    deviceId:"${data.deviceId}",
                    startTime:$("#startTime").val(),
                    productNum:$("#produtNum").val(),
                    goodNum:$("#goodNum").val(),
                    badNum:$("#badNum").val()
                }),
                success:function(data){
                    if(data.result == "SUCCESS"){
                        swal({
                            title: "<spring:message code="label.modify.success"/>",
                            text: "",
                            type: "success",
                            showCancelButton: false,
                            showConfirmButton: true,
                            confirmButtonText: "<spring:message code="label.admin.confirm"/>",
                            animation: "slide-from-top"
                        }, function () {
                            window.location.replace("/partner/{tenant}/product/list?deviceId=${data.deviceId}#deviceData".replace("{tenant}", getKeyByUrl()));
                        });
                    }else{
                        swal("Error!", data.message,"error");
                    }

                },
                error:function(){
                    swal("Error!", "", "error");
                }
            })
        })
    })
</script>